import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index')
    }]
  },

  // 管理员管理
  {
    path: '/admin',
    component: Layout,
    name: 'Admin',
    alwaysShow: true,
    redirect: '/admin/staff',
    meta: {
      title: '管理员管理'
    },
    children: [
      {
        path: 'staff',
        name: 'Staff',
        component: () => import('@/views/admin/staff.vue'),
        meta: { title: '员工列表' }
      },
      {
        path: 'addStaff',
        name: 'AddStaff',
        hidden: true,
        component: () => import('@/views/admin/components/staffDetail.vue'),
        meta: { title: '新增员工', isEdit: false }
      },
      {
        path: 'editStaff/:id',
        name: 'EditStaff',
        hidden: true,
        component: () => import('@/views/admin/components/staffDetail.vue'),
        meta: { title: '编辑员工', isEdit: true }
      }
    ]
  },

  // 商品管理
  {
    path: '/product',
    component: Layout,
    name: 'Product',
    alwaysShow: true,
    redirect: '/product/index',
    meta: {
      title: '商品管理'
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/product/index.vue'),
        meta: { title: '商品列表' }
      },
      {
        path: 'addProduct',
        name: 'AddProduct',
        hidden: true,
        component: () => import('@/views/product/components/productDetail.vue'),
        meta: { title: '添加商品', isEdit: false }
      },
      {
        path: 'editProduct/:id',
        name: 'EditProduct',
        hidden: true,
        component: () => import('@/views/product/components/productDetail.vue'),
        meta: { title: '编辑商品', isEdit: true }
      }
    ]
  },
  // 商品类别
  {
    path: '/category',
    component: Layout,
    name: 'Category',
    alwaysShow: true,
    redirect: '/category/index',
    meta: {
      title: '商品类别管理'
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/category/index.vue'),
        meta: { title: '商品类别'}
      },
      {
        path: 'addCategory',
        name: 'AddCategory',
        hidden: true,
        component: () => import('@/views/category/components/categoryDetail.vue'),
        meta: { title: '添加类别', isEdit: false}
      },
      {
        path: 'editCategory/:id',
        name: 'EditCategory',
        hidden: true,
        component: () => import('@/views/category/components/categoryDetail.vue'),
        meta: { title: '编辑类别', isEdit: true}
      },
    ]
  },
  {
    path: '/categoryDetail',
    component: Layout,
    name: 'CategoryDetail',
    alwaysShow: true,
    redirect: '/categoryDetail/index',
    meta: {
      title: '商品类别明细管理'
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/categoryDetail/index.vue'),
        meta: { title: '商品类别明细'}
      },
      {
        path: 'addCategoryDetail',
        name: 'AddCategoryDetail',
        hidden: true,
        component: () => import('@/views/categoryDetail/components/category.vue'),
        meta: { title: '添加类别明细', isEdit: false}
      },
      {
        path: 'editCategoryDetail/:id',
        name: 'EditCategoryDetail',
        hidden: true,
        component: () => import('@/views/categoryDetail/components/category.vue'),
        meta: { title: '编辑类别明细', isEdit: true}
      },
    ]
  },
  // 用户管理
  {
    path: '/user',
    component: Layout,
    name: 'User',
    alwaysShow: true,
    redirect: '/user/index',
    meta: {
      title: '用户管理'
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/user/index.vue'),
        meta: { title: '用户列表' }
      },
      {
        path: 'userDetail/:id',
        name: 'UserDetail',
        hidden: true,
        component: () => import('@/views/user/components/userDetail.vue'),
        meta: { title: '用户详情' }
      }
    ]
  },
  // 订单管理
  {
    path: '/order',
    component: Layout,
    name: 'Order',
    alwaysShow: true,
    redirect: '/order/index',
    meta: {
      title: '订单管理'
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/order/index.vue'),
        meta: { title: '订单列表'}
      },
      {
        path: 'orderDetail/:id',
        name: 'OrderDetail',
        hidden: true,
        component: () => import('@/views/order/components/orderDetail.vue'),
        meta: { title: '订单列表详情'}
      }
    ]
  },
  // 销售管理
  {
    path: '/sell',
    component: Layout,
    name: 'Sell',
    alwaysShow: true,
    redirect: '/sell/index',
    meta: {
      title: '销售管理'
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/sell/index.vue'),
        meta: { title: '销售明细' }
      }
    ]
  },
  // banner管理
  {
    path: '/banner',
    component: Layout,
    name: 'Banner',
    alwaysShow: true,
    redirect: '/banner/index',
    meta: {
      title: '首页banner管理'
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/banner/index.vue'),
        meta: { title: 'banner列表' }
      },
      {
        path: 'addBanner',
        name: 'AddBanner',
        hidden: true,
        component: () => import('@/views/banner/components/bannerDetail.vue'),
        meta: { title: '新增banner', isEdit: false }
      },
      {
        path: 'editBanner/:id',
        name: 'EditBanner',
        hidden: true,
        component: () => import('@/views/banner/components/bannerDetail.vue'),
        meta: { title: '编辑banner', isEdit: true }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
